#include "rooms.hh"

namespace rooms {
    spring_room::spring_room() {
        this->type = "Spring room";
    }

    spring_room::~spring_room() {
        
    }
    spring_room::spring_room(const spring_room& other) {
        this->type = other.type;
    }
    spring_room& spring_room::operator=(const spring_room& other) {
        this->type = other.type;
        return *this;
    }

    std::string spring_room::getType() {
        return this->type;
    }

    void spring_room::event(std::vector<ICharacter*>& hero_team) {
        IO::clearTerminal();
        std::cout << "------" << this->type << "------"  << "\n";
        IO::getString("Enter anything to contiune.");
        IO::clearTerminal();
        gamefunction::hot_spring(hero_team);
        IO::getString("Enter anything to enter next room.");
        IO::clearTerminal();
    }

    fight_room::fight_room() {
        this->type = "Fight room";
    }
    fight_room::~fight_room() {
        
    }

    fight_room::fight_room(const fight_room& other) {
        this->type = other.type;
    }
    fight_room& fight_room::operator=(const fight_room& other) {
        this->type = other.type;
        return *this;
    }
    
    std::string fight_room::getType() {
        return this->type;
    }
    
    void fight_room::event(std::vector<ICharacter*>& hero_team) {
        std::vector<ICharacter*> enemy_team;

        IO::clearTerminal();
        IO::clearTerminal();
        std::cout << "------" << this->type << "------"  << "\n";
        IO::getString("Enter anything to contiune.");
        IO::clearTerminal();
        enemy_team = gamefunction::get_random_fight();
        gamefunction::hole_fight(hero_team, enemy_team);
        IO::getString("Enter anything to enter next room.");
        IO::clearTerminal();
    }

    empty_room::empty_room() {
        this->type = "Empty room";
    }
    empty_room::~empty_room() {
        
    }

    empty_room::empty_room(const empty_room& other) {
        this->type = other.type;
    }
    empty_room& empty_room::operator=(const empty_room& other) {
        this->type = other.type;
        return *this;
    }
    
    std::string empty_room::getType() {
        return this->type;
    }
    
    void empty_room::event(std::vector<ICharacter*>& hero_team) {
        IO::clearTerminal();
        std::cout << "------" << this->type << "------"  << "\n";
        std::cout << "Nothing happen..." << "\n";
        IO::getString("Enter anything to enter next room.");
        IO::clearTerminal();
    }

    item_room::item_room() {
        this->type = "item room";
    }
    item_room::~item_room() {
        
    }
    
    item_room::item_room(const item_room& other) {
        this->type = other.type;
    }
    item_room& item_room::operator=(const item_room& other) {
        this->type = other.type;
        return *this;
    }
    
    std::string item_room::getType() {
        return this->type;
    }
    
    void item_room::event(std::vector<ICharacter*>& hero_team) {
        int random_num = randomFunc::get_Random_Num(1, 4);
        unsigned hero_pos;
        Item::Item random_item;
        IO::clearTerminal();
        std::cout << "------" << this->type << "------"  << "\n";
        IO::getString("Enter anything to continue.");
        IO::clearTerminal();
        switch (random_num) {
            case 1: random_item = Item::HealingPotion; break;
            case 2: random_item = Item::StressReliever; break;
            case 3: random_item = Item::SpeedBoost; break;
            case 4: random_item = Item::AttackBoost; break;
            default: random_item = Item::HealingPotion; break;
        }
        std::cout << "There's a " << random_item.name << " in this room.\n";
        std::cout << random_item.description << "\n";

        IO::display_hero_teams_massage(hero_team);
        hero_pos = IO::getUnsignedInt(1, hero_team.size(), "Enter hero's postion in team to let hero use this item.") - 1;

        if (auto* h = dynamic_cast<Ahero*>(hero_team[hero_pos])) {
            random_item.effect(*h);
        }
        IO::clearTerminal();
        std::cout << hero_team[hero_pos]->getName() << " use " << random_item.name << ".\n";


        IO::getString("Enter anything to enter next room.");
        IO::clearTerminal();
    }
}
